package com.parking.status.sync.netty.client;

import com.parking.status.sync.netty.entity.ResponsePre;
import com.parking.status.sync.netty.event.ResponseReceivedEvent;
import com.parking.status.sync.netty.event.ResponseReceivedEventParameters;
import com.parking.status.sync.netty.service.EventPublishService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2015/9/18.
 */
@ChannelHandler.Sharable
public class ResponseFinalDecoder extends MessageToMessageDecoder<ResponsePre> {

    @Autowired
    private EventPublishService service;// = new EventPublishService();

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ResponsePre response, List<Object> out) throws Exception {


        ResponseReceivedEvent event = new ResponseReceivedEvent(
                new ResponseReceivedEventParameters(channelHandlerContext, response));
        service.publishEvent(event);
    }
}
